import {del, get, post, put} from "@/api/base/http";
import {ApiUri} from "@/api/base/ApiPath";

let ApiPath = new ApiUri();

export class GlobalParam {
    /**
     * 新增变量
     * @param Param
     * @param Callback
     * @constructor
     */
    static AddGlobalParam(Param: object) {
        return post(ApiPath.GlobalParam.ROOT, Param)
    }

    static DeleteGlobalParam(Id: number) {
        return del(ApiPath.GlobalParam.ROOT + Id)
    }

    /**
     * 批量更新全局变量
     * @param Param
     * @param Callback
     * @constructor
     */
    static UpdateGlobalParams(Params: object) {
        return put(ApiPath.GlobalParam.BATCH_UPDATE, Params)
    }

    /**
     * 更新全局变量
     * 格式
     * {Name: Update.nodeParam, Value: _Val}
     * @param Param
     * @constructor
     */
    static UpdateGlobalParam(Param: object) {
        return put(ApiPath.GlobalParam.ROOT, Param)
    }

    /**
     * 获取所有全局变量
     * @constructor
     */
    static GetGlobalParams() {
        return get(ApiPath.GlobalParam.ROOT)
    }

    /**
     * 根据全局变量的参数名称获取全局变量的完整信息
     * @param Params:['name1','name2']
     * @param Callback
     * @constructor
     */
    static GetGlobalParam(Params: string[], Callback: Function) {
        get(ApiPath.GlobalParam.ROOT).then(res => {
            const _res = res.Data
            const target = []
            for (let re of _res) {
                if (typeof Params == 'string') {
                    if (Params == re.Name) {
                        target.push(re)
                        break
                    }
                } else {
                    target.push(re)
                }
            }
            Callback && Callback(target)
        })
    }
}

